package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理项目相关接口")
public class NursingProjectController extends BaseController {
    @Autowired
    NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation(value = "护理项目分页查询", notes = "根据名称和状态进行分页查询护理项目信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "项目名称", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "int", paramType = "query", defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "int", paramType = "query", defaultValue = "10"),
            @ApiImplicitParam(name = "status", value = "项目状态", dataType = "int", paramType = "query")
    })
    public ResponseResult pageFind(@RequestParam(value = "name", required = false) String name,
                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                   @RequestParam(value = "status", required = false) Integer status) {
        PageResponse<NursingProjectVo> nursingProjects = nursingProjectService.pageFind(name, pageNum, pageSize, status);
        log.info("项目分页查询的结果:{}",nursingProjects);
        return success(nursingProjects);
    }

@PostMapping
    @ApiOperation(value = "新增护理项目", notes = "新增护理项目")
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto){
        log.info("新增护理项目的数据:{}",nursingProjectDto);
        nursingProjectService.add(nursingProjectDto);
        return success();
    }



    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理项目", notes = "根据id查询护理项目")
    public ResponseResult<NursingProjectVo> ById(@PathVariable Long id){
        log.info("根据id查询护理项目的id:{}",id);
        NursingProjectVo nursingProjectVo = nursingProjectService.ById(id);
        return success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation(value = "修改护理项目", notes = "修改护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        log.info("修改护理项目数据:修改参数:{}",nursingProjectDto);
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理项目", notes = "删除护理项目")
    public ResponseResult delete(@PathVariable Long id){
            log.info("删除护理项目id:{}",id);
            nursingProjectService.delete(id);

            return success();
    }


    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "修改护理项目状态", notes = "修改护理项目状态")
    public ResponseResult updatestatus(@PathVariable Long id,@PathVariable Integer status){

        nursingProjectService.updatestatus(id,status);
        return success();
    }


    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目", notes = "查询所有护理项目")
    public ResponseResult<List<NursingProject>> all(){
        List<NursingProject> nursingProject=nursingProjectService.all();
        return success(nursingProject);
    }
}
